

//游戏类型
enum GameType {
    shenyang = 2, tieling = 10, dandong = 11, panshi = 12, jinan = 34, chifeng = 36, baotou = 38,
    hunchun = 43, baishan = 41, hailun = 47, bayan = 55,
    sichuan = 100
}

/**
  * 游戏配置文件
  */
class GameConfig {
    //========================================外部配置数据========================================

    //----------------------------------微信相关----------------------------------
    //appid
    static appid: string = "wx1310f5f590acf9d5";
    //微信联系人
    static wx_contact: string = "hlscmj01";

    //----------------------------------地址相关----------------------------------
    //客户端地址
    static client_addr: string = "weixinhlmj.37gjw.com/chuanma/";

    //服务器地址
    //static server_addr: string = "sichuan01.37gjw.com";
    static server_addr: string = "lyqptest.h5sd.com";
    //服务器端口

    static server_port: number = 10427;


    //ip配置地址
    static ip_addr: string = "https://getip.h5sd.com:8143/";

    //更多游戏跳转链接
    static moregame_href: string = 'http://www.wishstart.com/mjzx/game.html';
    //招募代理资源地址
    static recruit_href: string = 'https://godlike.h5qlyx.com/recruit/';
    //招募代理跳转地址
    static recruit_skip: string;
    //提现跳转链接
    static money_href: string = 'https://mp.weixin.qq.com/s/2EFWBfnJ_ZzIkBKaAhiyDg';
    //客服跳转链接
    static kefu_href: string = '';

    //客户端季节资源地址
    static client_season: string = 'https://godlike.h5qlyx.com/mjdynamic/skin/summer/';
    //客户端区域资源地址
    static client_area: string;

    //----------------------------------活动相关----------------------------------
    //活动列表
    static active_list: any[] = [];
    //活动跳转
    static active_to: number = 1;

    //----------------------------------福利相关----------------------------------
    //福利列表
    static welfare_list: any[] = [];
    //福利页面跳转链接
    static welfare_href: string = 'http://lyqpgm.wishstart.com.cn/bflyhd/test.html';

    //----------------------------------游戏公告----------------------------------
    //公告时间
    static notice_time: number = 120;
    //公告列表
    static notice_list: any[] = [];
    //停服公告
    static notice_noservice: any[] = [];

    //----------------------------------游戏相关----------------------------------
    //版本号
    static version: string = '1.0.1';
    //版本号-资源
    static version_res: string = '1.0.1';
    //版本号-cookies
    static version_cookies: string = '1.0.1';

    //版权所有
    static copyright: any = {
        banhao: '',
        wangwen: '京网文[2016]2511-293号',
        icp: '京ICP备案11038507号-7',
        gongwang: '京公网安备11010802024284号',
        wangyou: '文网游备字[2017]M-CBG 1234号',
    };

    //错误代码提示
    static errorCodes: any = {
        1: "人已经满了！",
        2: "牌局已经开始了！",
        3: "房间不存在或已过期！",
        4: "参数不合法",
        5: "状态不合法",
        6: "已经在房间里了",
        7: "查无此人",
        8: "不能绑定你自己",
        9: "你已经有代理了",
        10: "不支持此房间类型",
        11: "关系错误",
        12: "密码错误",
        13: "您的房卡不够",
        14: "记录已过期",
        15: "签名失败",
        16: "权限不足",
        17: "您已经投过票了",
        18: "未知错误",
        19: "数字溢出(超出 你已经拥有的)",
        20: "最多只能同时开启10个空闲房间",
        21: "房卡数量低于100张时不能开启房间",
        31: "刚有人拒绝了解散申请，请稍后再试",
        51: "认证失败",
        52: "牌局已开始,请稍候重试!",
        53: "牌局已开始,请稍候重试!",
        54: "牌局已开始,请稍候重试!",
        55: "操作过于频繁，请稍后再试",
        56: "操作过于频繁，请稍后再试",
        57: "网络状态不稳定",
        58: "网络状态不稳定",
        /**老友圈 */
        1001: "没有游戏账号",
        1002: "登陆失败，此种重新拉授权",
        1003: "短信验证码错误",
        1004: "请求太频繁",
        1005: "房卡数量不够建立圈子",
        1006: "一个地区只能建10个圈子",
        1007: "人数大于1的圈子不能解散",
        1008: "查无此人",
        1009: "没有这个圈子",
        1010: "已经在这个圈子里了",
        1011: "已经申请过了",
        1012: "圈子已经满了",
        1013: "最多只能加入1个圈子",
        1014: "您没有圈子或已被踢出",
        1015: "不能移除自己",
        1016: "不是圈主",
        1017: "查无记录",
        1019: "退出申请已提交",
        1020: "申请成功，等待圈主同意即可进入到圈子",
        1021: "修改规则成功",
        1023: "圈主剩余房卡不足，无法开启新牌局",
        1025: "您已经被圈主限制进入，请及时联系圈主。"
    };

    //功能开关-登录页面
    static switch_login: boolean = true;
    //功能开关-红包
    static switch_hongbao: boolean = false;
    //功能开关-代开房
    static switch_daikaifang: boolean = true;
    //功能开关-手机认证
    static switch_shoujirenzheng: boolean = true;

    //功能开关-更多游戏
    static switch_moregames: boolean = true;
    //功能开关-同ip提示
    static switch_sameip: boolean = true;
    //功能开关-客服
    static switch_kefu: boolean = true;
    //功能开关-测距
    static switch_distance: boolean = true;
    //功能开关-福利
    static switch_welfare: boolean = false;
    //老友圈
    static switch_circle: boolean = true;

    //玩法介绍
    static introduction: any = {};

    //分支信息
    static branch_info: any = {};

    //导入外部配置信息
    static appendConfig(config) {
        if (config) {
            for (let key in config) {
                GameConfig[key] = config[key];
            }
        }
    }

    //========================================组合数据========================================
    //客户端地址
    static clientUrl: string;
    //默认分享图标
    static shareIconUrl: string;
    //代开房分享图标
    static daikaiShareIconUrl: string;
    //回放分享图标
    static replayShareIconUrl: string;
    //圈子图标
    static circleShareIconUrl: string;
    //老友圈文案
    static circleDescJoin: string = "加入老友圈,更快更方便!圈主支付,无需充卡;自动开房,点击即玩.";
    static circleDescJoinBottom: string = "可通过输入圈子ID进行加入,也可以进入公众号创建新的圈子";
    // //服务器地址
    // static servertest_addr: string = "lyqptest.h5sd.com";
    // //服务器端口
    // static servertest_port: number = 10775;

    //服务器地址
    static servertest_addr: string = "192.168.2.251";
    //服务器端口
    // static servertest_port: number = 10427;
    static servertest_port: number = 15415;

    //========================================游戏数据========================================

    //麻将类型
    static gameType: GameType = GameType.shenyang;
    //麻将名字
    static mahjong_name: string = '边锋老友沈阳麻将';
    //通用资源列表
    static res_common_list: string[] = [
        'game_scene.jpg', 'main_other_girl.png', 'game_logo_startup.png',
        'main_btn_laoyouquan.png', 'main_btn_welfare.png', 'main_room_create.png', 'main_room_joinin.png'
    ];
    //游戏资源列表
    static res_game_list: string[] = [
        'game_logo_login.png', 'game_name_02.png',
        'icon_share.png', 'icon_daikai.png', 'icon_playback.png'
    ];
    //资源配置
    static res_config: any = {};

    //有宝牌
    static hasBao: boolean = false;
    //自动胡牌
    static autoHu: boolean = false;
    //暗杠显示
    static angangShow: boolean = false;
    //开牌补花
    static kaipaibuhua: boolean = false;
    //提示剩余牌
    static tipsLastCards: boolean = false;
    //是否纯净版显示
    static isPureness: boolean = false;

    //微信回调code
    static wx_code: string;

    //初始化
    static init() {

        this.wx_code = StringUtils.getUrlParams("code");

        game.ip = StringUtils.getUrlParams("ip");
        game.port = StringUtils.getUrlParams("port");
        game.user = StringUtils.getUrlParams("users");
        game.branch = StringUtils.getUrlParams("branch");
        game.roomid = +StringUtils.getUrlParams("roomid");
        game.roomCreateTime = +StringUtils.getUrlParams("createtime");

        Replayer.shareIF.uid = StringUtils.getUrlParams("uid");
        Replayer.shareIF.item_id = StringUtils.getUrlParams("item_id");
        Replayer.shareIF.playback_id = StringUtils.getUrlParams("playback_id");

        if (Replayer.shareIF.uid) Replayer.shareIF.isSharePlayback = true;

        //TODO 新分支信息
        if (GameConfig.branch_info && game.branch && GameConfig.branch_info.hasOwnProperty(game.branch)) {
            GameConfig.appendConfig(GameConfig.branch_info[game.branch]);
        }

        document.title = '' + GameConfig.mahjong_name;

        GameConfig.clientUrl = GameConfig.client_addr + (StringUtils.getUrlParams("accessType") == "test" ? "test.html" : "game.html");
        GameConfig.shareIconUrl = GameConfig.client_area + "icon_share.png";
        GameConfig.daikaiShareIconUrl = GameConfig.client_area + "icon_daikai.png";
        GameConfig.replayShareIconUrl = GameConfig.client_area + "icon_playback.png";
        GameConfig.circleShareIconUrl = GameConfig.client_area + "icon_circle.png";
        if (this.wx_code) {
            GameStorage.delData(GameStorage.wx_code);
        }
        else {
            this.wx_code = GameStorage.getData(GameStorage.wx_code);
        }

        GameConfig.ipConfig();
    }

    //初始化分享信息
    static initShare(daikai: boolean = false) {
        if (+game.roomid > 1000) {
            Weixin.shareGame('' + game.roomid, daikai);
            Weixin.shareGameToTimeline('' + game.roomid, daikai);
        }
        else {
            if (game.roomState == RoomState.CIRCLE) {
                Weixin.onCircleJoinShare();
                Weixin.circleShareGameToTimeline();
            } else {
                Weixin.shareGame();
                Weixin.shareGameToTimeline();
            }

        }
    }

    //微信授权
    static wxAccess() {
        if (!this.wx_code && Replayer.shareIF.uid) {
            Weixin.getAccessCode(GameConfig.appid, Weixin.shareUrl(2));
            return;
        }

        if (!this.wx_code && !game.user) {
            Weixin.getAccessCode(GameConfig.appid, Weixin.shareUrl(1));
            return;
        }
    }

    //微信授权信息配置
    // static wxConfig() {
    //     let action: any = {
    //         gameid: GameConfig.gameType,
    //         roleinfo: "user",
    //         mod: "mod_auths",
    //         fun: "auth_signature",
    //         args: {}
    //     };
    //
    //     let arr: Array<string> = ["closeWindow", "hideMenuItems", "getLocation", "onMenuShareAppMessage", "onMenuShareTimeline", "startRecord", "stopRecord", "onVoiceRecordEnd", "playVoice", "pauseVoice", "stopVoice", "onVoicePlayEnd", "uploadVoice", "downloadVoice"];
    //
    //     HttpNetwork.pull(GameConfig.wx_access_addr + ":" + GameConfig.wx_access_port, function (obj) {
    //         if (obj.message != "error") {
    //             let data: any = JSON.parse(obj.message);
    //             Weixin.config(
    //                 GameConfig.appid,
    //                 data.timestamp,
    //                 data.noncestr,
    //                 data.signature,
    //                 arr
    //             );
    //         }
    //     }, this, "action=" + JSON.stringify(action));
    // }

    //IP配置
    static ipConfig() {
        let action = {
            gameid: GameConfig.gameType,
            openid: null
        };

        if (game.user) {
            action.openid = game.user;
        }
        else if (!GameStorage.getData(GameStorage.wx_code)) {
            action.openid = GameConfig.wx_code;
        }
        else if (GameStorage.getData(GameStorage.uid)) {
            action.openid = GameStorage.getData(GameStorage.uid);
        }

        HttpNetwork.pull(GameConfig.ip_addr, null, this, "action=" + JSON.stringify(action));
    }
}